﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;

namespace DA
{
    // lớp cơ sở để tạo kết nốt đến DB
    public class DBConnection
    {
        private const string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\test\Desktop\QLDO\QLDO.mdf;Integrated Security=True;Connect Timeout=30";
        private SqlConnection _sqlConnection;

        public SqlConnection sqlConnection
        {
            get { return _sqlConnection; }
        }
        protected SqlCommand sqlCommand;
        protected SqlDataReader sqlDataReader;
        protected SqlDataAdapter sqlDataAdapter;

        // hàm tạo mặc định
        public DBConnection()
        {
            _sqlConnection = new SqlConnection(connectionString);
            sqlCommand = new SqlCommand();
            sqlDataAdapter = new SqlDataAdapter();
        }
        // mở kết nối
        public bool open()
        {
            try
            {
                sqlConnection.Open();
                return true;
            }
            catch
            {
                return false;
            }
        }
        // đóng kết nối
        public bool close()
        {
            try
            {
                sqlConnection.Close();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }   
}
